package xhwl.insurance.ui;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import xhwl.android.common.util.StringUtil;
import xhwl.insurance.BaseActivity;
import xhwl.insurance.Constant;
import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.ProcessListResp;
import xhwl.insurance.util.AppUtil;
import xhwl.insurance.view.ForumPictureView;

public class CardDealDetialActivity extends BaseActivity implements View.OnClickListener {

    public static final String BEAN = "bean";
    TextView status, produce, time, name, mobile, cardNum;
    ProcessListResp bean;
    private TextView mCardNum;
    private String card_front, card_back, card_number_pic;
    private ImageView id_front;
    private ImageView id_back;
    private ImageView hmo_pic;

//    List<String> mPictureList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bean = (ProcessListResp) getIntent().getSerializableExtra(BEAN);
        setContentView(R.layout.activity_card_deal_detial);
    }

    @Override
    public void initViews() {
        initTitleViews();
        status = (TextView) findViewById(R.id.detail_status);
        produce = (TextView) findViewById(R.id.detail_produce);
//        time = (TextView) findViewById(R.id.detail_time);
        mCardNum = (TextView) findViewById(R.id.tv_hmo_card_num);
        name = (TextView) findViewById(R.id.detail_name);
        mobile = (TextView) findViewById(R.id.detail_mobile);
        cardNum = (TextView) findViewById(R.id.detail_card);
        id_front = (ImageView) findViewById(R.id.id_front);
        id_back = (ImageView) findViewById(R.id.id_back);
        hmo_pic = (ImageView) findViewById(R.id.hmo_pic);
        if (bean == null) {
            return;
        }
        //orderStatus中0-处理中，1-成功，3-无效
        if ("处理中".equals(bean.getORDER_STATUS())) {
            status.setTextColor(getResources().getColor(R.color.orange));
        } else if ("成功".equals(bean.getORDER_STATUS())) {
            status.setTextColor(getResources().getColor(R.color.green));
        } else if ("无效".equals(bean.getORDER_STATUS())) {
            status.setTextColor(getResources().getColor(R.color.hintgray));
        }


        status.setText(voildEmptyData(bean.getORDER_STATUS()));
        produce.setText(voildEmptyData(bean.getSALE_NAME()));
//        time.setText(voildEmptyData(bean.getCREATE_DATE()));
        mCardNum.setText(voildEmptyData(bean.getCARD_NUMBER()));
        name.setText(voildEmptyData(bean.getPERSON_NAME()));
        if (bean.getPERSON_MOBILE().length() == 11) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bean.getPERSON_MOBILE().length(); i++) {
                char c = bean.getPERSON_MOBILE().charAt(i);
                if (i >= 3 && i <= 6) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
            bean.setPERSON_MOBILE(sb.toString());
        }
        mobile.setText(voildEmptyData(bean.getPERSON_MOBILE()));
        if (bean.getPERSON_IDCARD().length() == 18) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bean.getPERSON_IDCARD().length(); i++) {
                char c = bean.getPERSON_IDCARD().charAt(i);
                if (i >= 3 && i <= 13) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
            bean.setPERSON_IDCARD(sb.toString());
        }
        cardNum.setText(voildEmptyData(bean.getPERSON_IDCARD()));

        if (!StringUtil.isEmpty(bean.CARD_PIC_FORNT)) {
            card_front = bean.CARD_PIC_FORNT;

            Glide.with(mContext)
                    .load(card_front)
                    .error(R.drawable.pic_add)
                    .into(id_front);
        }
        if (!StringUtil.isEmpty(bean.CARD_PIC_BACK)) {
            card_back = bean.CARD_PIC_BACK;
            Glide.with(mContext)
                    .load(card_back)
                    .error(R.drawable.pic_add)
                    .into(id_back);
        }
        if (!StringUtil.isEmpty(bean.CARD_NUMBER_PIC)) {
            card_number_pic = bean.CARD_NUMBER_PIC;

            Glide.with(mContext)
                    .load(card_number_pic)
                    .error(R.drawable.pic_add)
                    .into(hmo_pic);
        }
    }


    @Override
    protected void setUpTitleView() {
        super.setUpTitleView();
        titleTextView.setText("明细详情");
    }

    @Override
    public void initListener() {
        id_front.setOnClickListener(this);
        id_back.setOnClickListener(this);
        hmo_pic.setOnClickListener(this);

    }

    @Override
    public void loadData() {

    }

    public String voildEmptyData(String str) {
        if (StringUtil.isEmpty(str)) {
            return "未知";
        } else
            return str;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.id_front:
                Intent intent = new Intent(this, PictureSlideActivity.class);
                intent.putExtra("imgshow", bean.CARD_PIC_FORNT);
                intent.putExtra("imgshow2", bean.CARD_PIC_BACK);
                intent.putExtra("imgshow3", bean.CARD_NUMBER_PIC);
                intent.putExtra("type", "1");
                startActivity(intent);
                break;
            case R.id.id_back:
                Intent intent2 = new Intent(this, PictureSlideActivity.class);
                intent2.putExtra("imgshow", bean.CARD_PIC_FORNT);
                intent2.putExtra("imgshow2", bean.CARD_PIC_BACK);
                intent2.putExtra("imgshow3", bean.CARD_NUMBER_PIC);
                intent2.putExtra("type", "2");
                startActivity(intent2);
                break;
            case R.id.hmo_pic:
                Intent intent3 = new Intent(this, PictureSlideActivity.class);
                intent3.putExtra("imgshow", bean.CARD_PIC_FORNT);
                intent3.putExtra("imgshow2", bean.CARD_PIC_BACK);
                intent3.putExtra("imgshow3", bean.CARD_NUMBER_PIC);
                intent3.putExtra("type", "3");
                startActivity(intent3);
                break;

            default:
                break;
        }

    }
}
